/* 
 * Illustrates input data verification/validation (uses Type.java)
 * Suggested exercises:
 * - change the type of intervals (open/close) 
 * - use if-else to read and validate a percentage value 
 *   (integer in the interval [0,100])
*/ 

import java.util.Scanner;

class CheckInput
{
    public static void main (String[] args) 
    {
      String input;
      int a;
      double x;
      Scanner scan = new Scanner(System.in);

      System.out.print("Enter an integer: ");
      a = scan.nextInt();

// Check intervals - boolean expression
      System.out.println(a + " belongs to [0,10]: " + (a>=0 && a<=10));
      System.out.println(a + " does not belong to [0,10]: " + (a<0 || a>10));
      System.out.println();
      
// Check intervals - if statement
      if (a>=0 && a<=10) 
        System.out.println(a + " belongs to [0,10]");
      if (a<0 || a>10)
        System.out.println(a + " does not belong to [0,10]");      

// Check intervals - if-else statement
      if (a>=0 && a<=10) 
        System.out.println(a + " belongs to [0,10]");
      else
        System.out.println(a + " does not belong to [0,10]");

// Check for input type  
      System.out.print("\nEnter an item: ");
      input = scan.next();
      
      System.out.println("Integer: " + Type.isInteger(input));
      System.out.println("Double: " + Type.isDouble(input));
      System.out.println();
      
      if (Type.isInteger(input)) 
        System.out.println(input + " is of type Integer");
      else
        if (Type.isDouble(input))
            System.out.println(input + " is of type Double");
        else
            System.out.println(input + " is of type String");

// Get the numeric value from string using a wrapper class method          
      if (Type.isInteger(input)) 
            System.out.println("The value of the integer + 1 is " + (Integer.valueOf(input)+1));
            
    }
  
}
